<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .centered-placeholder {
            width: 80%;
            font-size: 16px;
            text-align: center;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            涂装下线确认
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">滑橇号</div>
                    <input type="text" class="aui-input" placeholder="请输入滑橇号" readonly
                        style="width: 80%;font-size: 16px;" id="skiddingCode" />
                </div>
            </li>
            <li class="aui-list-item" style="background-color: #D7D7D7;">
                <div class="aui-list-item-inner">
                    <input type="text" class="aui-input centered-placeholder" placeholder="提示消息" readonly
                        style="color: black; font-size: 12px;" id="message" />
                </div>
            </li>

        </ul>

        <div id="table1">

        </div>
    </div>

    <footer>
        <div class="aui-btn aui-btn-info aui-btn-block" style="background-color:red !important;color:#f5f5f5;"
            onclick="chooseUnbind()">不合格提报</div>
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin-top: 2%;" onclick="offlineConfirm()">确认下线</div>
    </footer>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var seqNo = "";
    var arrSave = [];
    var num = 0;
    var mrlnum = 0;
    //初始化查询仓库下拉框
    apiready = function () {
        $("#skiddingCode").val(api.pageParam.skiddingCode)
        seqNo = api.pageParam.seq
        search()
    }
    function search() {
        var arrSave = [];
        var skiddingCode = $("#skiddingCode").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');

        var url = serverUrl + "/app/getLineOnOffRecord";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                skiddingCode: skiddingCode,
                seq: seqNo,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    if (list.length > 0) {
                        setTable(list)
                    } else {
                        api.toast({
                            msg: "请先维护治具与滑橇绑定关系！",
                            duration: 3000
                        });
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    function offlineConfirm() {
        api.confirm({
            title: '温馨提示',
            msg: '您确定要完成滑橇号' + api.pageParam.skiddingCode + '的下线确认吗？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                savePlan()
            }
        });
    }
    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += '<ul class="aui-list aui-form-list">'
            html += '<li class="aui-list-item" style="background-color: #03a9f4;">'
            html += '<div class="aui-list-item-inner" >'
            html += '<input type="text" class="aui-input" style="width: 80%;font-size: 14px;" readonly id="skiddingCode" value="' + '层数：' + list[i].level + '&nbsp' + '治具：' + list[i].fixtureCode + '(容量：' + list[i].numTotal + ')' + '">'
            html += '</input>'
            // html += '<div class="aui-btn aui-btn-info" style="width:25% ;margin-right:2%;background-color:red !important;color:#f5f5f5;" onclick="chooseUnbind()">不合格提报</div>'  
            html += '</div>'
            html += '</li>'
            html += '</ul>'

            html += '<div style="background-color:white; width: 100%;white-space: nowrap;overflow: auto;-webkit-overflow-scrolling:touch;">'
            html += '<table class="table" style="width:1050px;" >'
            html += '<tbody style="display:block;overflow-x: scroll;" >'
            html += '<tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">'
            html += '<td algin="center" style="width:20px;"></td>'
            // html += '<td algin="center" style="width:40px;">序号</td>'
            html += '<td algin="center" style="width:40px;display: none"></td>'
            html += '<td algin="center" style="width:100px;display: none" >容器条码</td>'
            html += '<td algin="center" style="width:130px;">规格</td>'
            html += '<td algin="center" style="width:200px;">物料名称</td>'
            html += '<td algin="center" style="width:100px;">物料编码</td>'
            html += '<td algin="center" style="width:50px;">数量</td>'
            html += '<td algin="center" style="width:100px;">合格数量</td>'
            html += '<td algin="center" style="width:150px;">不合格数量</td>'
            html += '<td algin="center" style="width:100px;">批次号</td>'
            html += '<td algin="center" style="width:150px;">上线时间</td>'
            html += '</tr>'
            html += '</tbody>'
            html += '<tfoot style="display: block;overflow-x: scroll;">'
            if (list[i].onlineRecordList.length > 0) {
                var onlineRecordListNew = list[i].onlineRecordList
                var j
                for (j = 0; j < onlineRecordListNew.length; j++) {
                    html += '<tr style="text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;">'
                    html += '<td algin="center" style="width:20px;"><input name="sub" type="checkbox"/></td>'
                    // html += '<td algin="center" style="width:40px;" name="level" >' + (j + 1) + '</td>'
                    html += '<td algin="center" style="width:40px;display: none" name="sysid" >' + onlineRecordListNew[j].sysid + '</td>'
                    html += '<td algin="center" style="width:100px;display: none" name= "produBarcode" >' + onlineRecordListNew[j].produBarcode + '</td>'
                    html += '<td algin="center" style="width:130px;" name="drawing">' + onlineRecordListNew[j].drawing + '</td>'
                    html += '<td algin="center" style="width:200px;" name="mrlName">' + onlineRecordListNew[j].mrlName + '</td>'
                    html += '<td algin="center" style="width:100px;" name="mrlCode">' + onlineRecordListNew[j].mrlCode + '</td>'
                    html += '<td algin="center" style="width:50px;">' + onlineRecordListNew[j].onlineQty + '</td>'
                    html += '<td algin="center" style="width:100px;" name="qualifyQty">' + onlineRecordListNew[j].qualifyQty + '</td>'
                    html += '<td algin="center" style="width:150px;">' + onlineRecordListNew[j].unQualifyQty + '</td>'
                    html += '<td algin="center" style="width:100px;" name="lotCode">' + onlineRecordListNew[j].lotCode + '</td>'
                    html += '<td algin="center" style="width:150px;">' + onlineRecordListNew[j].onlineDate + '</td>'
                    html += '</tr>'
                }
            } else {
                for (var j = 0; j < 1; j++) {
                    html += '<tr style="text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;">'
                    html += '<td algin="center" style="width:20px;"><input name="sub" type="checkbox"/></td>'
                    // html += '<td algin="center" style="width:40px;" name="level" >' + (j + 1) + '</td>'
                    html += '<td algin="center" style="width:40px;display: none" name="sysid" >' + '</td>'
                    html += '<td algin="center" style="width:130px;" name="drawing">' + '</td>'
                    html += '<td algin="center" style="width:200px;" name="mrlName">' + '</td>'
                    html += '<td algin="center" style="width:100px;display: none" name= "produBarcode" >' + '</td>'
                    html += '<td algin="center" style="width:100px;" name="mrlCode">' + '</td>'
                    html += '<td algin="center" style="width:50px;">' + '</td>'
                    html += '<td algin="center" style="width:100px;">' + '</td>'
                    html += '<td algin="center" style="width:150px;">' + '</td>'
                    html += '<td algin="center" style="width:100px;" name="lotCode">' + '</td>'
                    html += '<td algin="center" style="width:150px;">' + '</td>'
                    html += '</tr>'
                }
            }
            html += '</tfoot>'
            html += '</table>'
            html += '</div>'
            $api.html($api.byId("table1"), html);
        }
    };
    function chooseUnbind() {
        var levelCheck = ""
        var produBarcodeCheck = "";
        var mrlCodeCheck = "";
        var lotCodeCheck = "";
        var sysidCheck = ""
        var qualifyQtyCheck = ""
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var flag = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            levelCheck = row.find("[name='level']").html();
            sysidCheck = row.find("[name='sysid']").html();
            produBarcodeCheck = row.find("[name='produBarcode']").html();
            mrlCodeCheck = row.find("[name='mrlCode']").html();
            lotCodeCheck = row.find("[name='lotCode']").html();
            qualifyQtyCheck = row.find("[name='qualifyQty']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        if (sysidCheck == "" || sysidCheck == null || sysidCheck == undefined) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        var dialogBox = api.require('dialogBox');
        dialogBox.input({
            keyboardType: 'default',
            texts: {
                title: "不合格提报",
                placeholder: '请录入提报数量',
                leftBtnTitle: '取消',
                rightBtnTitle: '确定'
            },
            styles: {
                bg: '#fff',
                corner: 2,
                w: 300,
                h: 240,
                title: {
                    h: 60,
                    alignment: 'center',
                    size: 14,
                    color: '#000',
                    marginT: 30,
                },
                input: {
                    h: 60,
                    y: 30,
                    marginT: 15,
                    marginLeft: 10,
                    marginRight: 10,
                    textSize: 20,
                    textColor: '#000',
                    corner: 5,                  //（可选项）数字类型；对输入框圆角大小；默认：0

                },
                dividingLine: {
                    width: 0.5,
                    color: '#696969'
                },
                left: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40,                //(可选项) 数字类型；右边按钮的高度；默认：40
                    w: 60,                   //(可选项) 数字类型；左边按钮的宽度；默认：提示框的宽度的一半
                    marginB: 10,            //(可选项) 数字类型；左边按离底部的边距；默认：0
                    corner: 5,              //(可选项) 数字类型；左边按钮的圆角；默认：0
                    widhtBorder: 1,         //(可选项) 数字类型；左边按钮的边宽；默认：0
                    normalBorderColor: '#778899', //(可选项) 数字类型；左边按钮的边宽颜色；默认：'rgba(0,0,0,0)'
                    activeBorderColor: '#0000CD', //(可选项) 数字类型；左边按钮的高亮状态下边宽颜色；默认：'rgba(0,0,0,0)'
                    activeColor: '#006400', //(可选项) 数字类型；左边按钮的高亮状态下标题颜色；默认：'rgba(0,0,0,0)'
                    activeBg: '#6B8E23'   //(可选项) 数字类型；左边按钮的高亮状态下背景颜色；默认：'rgba(0,0,0,0)'
                },
                right: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40,                //(可选项) 数字类型；右边按钮的高度；默认：40
                    w: 60,                   //(可选项) 数字类型；右边按钮的宽度；默认：提示框的宽度的一半
                    marginB: 10,            //(可选项) 数字类型；右边按离底部的边距；默认：0
                    corner: 5,              //(可选项) 数字类型；右边按钮的圆角；默认：0
                    widhtBorder: 1,         //(可选项) 数字类型；右边按钮的边宽；默认：0
                    normalBorderColor: '#778899', //(可选项) 数字类型；右边按钮的边宽颜色；默认：'rgba(0,0,0,0)'
                    activeBorderColor: '#0000CD', //(可选项) 数字类型；右边按钮的高亮状态下边宽颜色；默认：'rgba(0,0,0,0)'
                    activeColor: '#006400', //(可选项) 数字类型；右边按钮的高亮状态下标题颜色；默认：'rgba(0,0,0,0)'
                    activeBg: '#6B8E23'   //(可选项) 数字类型；右边按钮的高亮状态下背景颜色；默认：'rgba(0,0,0,0)'
                }
            }
        }, function (ret) {
            var scrapQty = ret.text;

            //取消
            if (ret.eventType == 'left') {
                dialogBox.close({
                    dialogName: 'input'
                });
                //确定
            } else {
                //卡号必输校验
                if (scrapQty == null || scrapQty == "" || scrapQty == undefined) {
                    api.toast({
                        msg: "请录入提报数量!",
                        duration: 3000
                    });
                } else {
                    dialogBox.close({
                        dialogName: 'input'
                    });

                    if (parseInt(scrapQty) > parseInt(qualifyQtyCheck)) {
                        api.toast({
                            msg: "不合格提报数量" + scrapQty + "不允许大于可提报数量" + qualifyQtyCheck,
                            duration: 3000
                        });
                        return
                    }

                    var skiddingCode = $("#skiddingCode").val()
                    var un = localStorage.getItem('un');
                    var serverUrl = localStorage.getItem('serverUrl');
                    var url = serverUrl + "/app/saveUnqualifiedReporting";
                    var data = {
                        values: { ////以表单方式提交参数（JSON对象）
                            skiddingCode: skiddingCode,
                            level: levelCheck,
                            produBarcode: produBarcodeCheck,
                            mrlCode: mrlCodeCheck,
                            lotCode: lotCodeCheck,
                            scrapQty: scrapQty,
                            seq: seqNo,
                            sysid: sysidCheck,
                            un: un
                        }
                    };
                    api.ajax({
                        url: url,
                        method: 'post',
                        dataType: 'json',
                        timeout: 300,
                        returnAll: false,
                        data: data
                    }, function (ret, err) {
                        if (ret) {
                            var data = JSON.stringify(ret);
                            var myobj = eval("(" + data + ")");
                            if (myobj.code == '0') {
                                api.toast({
                                    msg: "提报成功！",
                                    duration: 3000
                                });
                                $("#message").val("提报成功")
                                search()
                            } else {
                                api.toast({
                                    msg: myobj.message,
                                    duration: 3000
                                });
                                $("#message").val(myobj.message)
                            }
                        }
                    });

                }
            }
        });
    }
    function savePlan() {
        var skiddingCode = $("#skiddingCode").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveOfflineConfirm";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                seq: seqNo,
                skiddingCode: skiddingCode,
                ZSType: 'lot',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    api.toast({
                        msg: "下线成功",
                        duration: 3000
                    });
                    api.closeWin()
                    api.execScript({
                        name: api.pageParam.name,
                        script: 'search()'
                    });
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#message").val(myobj.message)
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>